from setting import *
from gamebackground import *
from animation import *
from heroskill import *
from sys import exit
class MainScene(object):
    #初始化
    def __init__(self):
        pygame.mixer.pre_init()
        pygame.init()
        pygame.mixer.init()
        pygame.font.init()
        # pygame.mouse.set_visible(False)
        self.scene = pygame.display.set_mode((SCENEWIDTH, SCENEHEIGHT), 1, 32)
        # self.scene = pygame.display.set_mode((SCENEWIDTH, SCENEHEIGHT), pygame.FULLSCREEN, 32)
        pygame.display.set_caption("自学飞机大战--精灵组版")
       
        self.bground = Background(self.scene)
        h = HeroSkill(0)
        h.set_pos(SCENEWIDTH//2,SCENEHEIGHT//2)
        for v in range(0,4):
            a = HeroSkill(v)
            a.set_pos(random.randint(0,SCENEWIDTH-340),random.randint(0,SCENEHEIGHT-340))


        

    #绘制各个元素
    def draw(self):
        self.bground.draw()
        allgroup.draw(self.scene)

    def update(self):
        self.bground.update()
        allgroup.update()

    def collideEvent(self):
        pass

    #处理键盘和鼠标相应
    def handleEvent(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_j:
                    pass
                   
                else:
                    pass
               


    def runScene(self):
        # pygame.mixer.music.load('music/bgm.mp3')
        # pygame.mixer.music.play(-1)
        clock = pygame.time.Clock()
        while True:
            clock.tick(60)
            self.draw()
            self.update()
            self.collideEvent()
            self.handleEvent()
            pygame.display.flip()


if __name__ == "__main__":
    play = MainScene()
    play.runScene()

else:
    print("i was imported by", __name__)
